﻿using Avalonia.Threading;
using MyExe.Models;
using ReactiveUI;
using System;
using System.Collections.ObjectModel;
using System.Data.Common;
using System.Reactive;
using System.Threading.Tasks;
using System.Windows.Input;

namespace MyExe.ViewModels
{
    public partial class MainWindowViewModel : ViewModelBase
    {

        public ReactiveCommand<Unit, Unit> DataCommand { get; }
        public ReactiveCommand<Unit, Unit> SettingCommand { get; }
        public ReactiveCommand<Unit, Unit> RegisterCommand { get; }

        public MainWindowViewModel()
        {
            DataCommand = ReactiveCommand.Create(() =>
            {
                Console.WriteLine("按钮被点击");
            });
            SettingCommand = ReactiveCommand.Create(() =>
            {
                SettingWindow settingWindow = new SettingWindow();
                settingWindow.Show();
            });
            RegisterCommand = ReactiveCommand.CreateFromTask(async () =>
            {
                await Dispatcher.UIThread.InvokeAsync(async () =>
                {
                    RegisterWindow registerWindow = new RegisterWindow();
                    registerWindow.Show();
                });
    },
    outputScheduler: RxApp.MainThreadScheduler
);
        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private async Task DataCommandExecute()
        {
            await Dispatcher.UIThread.InvokeAsync(() =>
            {
            });
        }

        private void RegisterCommandExecute()
        {
            Dispatcher.UIThread.InvokeAsync(async () =>
            {
                var ss = "111";
            });
            //RegisterWindow registerWindow = new RegisterWindow();
            //registerWindow.Show();
        }

    }
}
